import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:roundcheckbox/roundcheckbox.dart';
import 'package:shenfuhui/entity/user_info_entity.dart';
import 'package:shenfuhui/routers/routers.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../config/config.dart';
import '../http/api.dart';
import '../provider/userinfo_provider.dart';
import '../views/number_controller_widget.dart';

///
/// 订单详情页面
///
class OrderDetailPage extends StatefulWidget {
  const OrderDetailPage({Key? key}) : super(key: key);

  @override
  State<OrderDetailPage> createState() => _OrderDetailPageState();
}

class _OrderDetailPageState extends State<OrderDetailPage> {
  var productList = [];
  var beizhu = '';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setState(() {
      productList.add("");
    });
  }

  getListItem(int index) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 20.w),
      height: 140.w,
      decoration: BoxDecoration(
        border:
            Border(bottom: BorderSide(color: Config.colorDivider, width: 1.w)),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            margin: EdgeInsets.only(right: 20.w),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(5),
              child: Image.network(
                "https://pic1.zhimg.com/v2-6438843a4cbae9184b935a75a5059ac6_1440w.jpg?source=172ae18b",
                fit: BoxFit.fill,
                width: 100.w,
                height: 100.w,
              ),
            ),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "商品名称",
                softWrap: true,
                style: TextStyle(color: (Config.colorText1), fontSize: 22.w),
              ),
              Container(
                width: 540.w,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "规格",
                      softWrap: true,
                      style:
                          TextStyle(color: (Config.colorText1), fontSize: 20.w),
                    ),
                    Text(
                      "X1",
                      softWrap: true,
                      style:
                          TextStyle(color: (Config.colorText1), fontSize: 20.w),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: EdgeInsets.only(top: 9.w),
              ),
              Text(
                "￥0.00",
                softWrap: true,
                style: TextStyle(color: (Config.colorText1), fontSize: 20.w),
              ),
            ],
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('订单详情'),
        centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        color: Config.colorBg2,
        height: double.infinity,
        child: Stack(
          children: [
            SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child: Column(
                children: [
                  Container(
                    //订单状态显示
                    margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
                    height: 100.w,
                    padding: EdgeInsets.symmetric(horizontal: 20.w),
                    decoration: BoxDecoration(
                      color: Config.colorWhite,
                      borderRadius: BorderRadius.circular(10.w),
                    ),
                    child: Row(
                      children: [
                        Icon(
                          Icons.check_circle,
                          size: 32.w,
                          color: Config.colorMain,
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 20.w),
                        ),
                        Text(
                          "支付完成，待商家发货",
                          style: TextStyle(
                              fontSize: 24.sp, color: Config.colorMain),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    //收货信息
                    margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
                    decoration: BoxDecoration(
                      color: Config.colorWhite,
                      borderRadius: BorderRadius.circular(10.w),
                    ),
                    width: double.infinity,
                    padding:
                        EdgeInsets.symmetric(vertical: 20.w, horizontal: 25.w),
                    child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              "收货人：大飞哥哥",
                              style: TextStyle(fontSize: 24.sp),
                            ),
                            Text(
                              "18088550000",
                              style: TextStyle(fontSize: 24.sp),
                            ),
                          ],
                        ),
                        Padding(
                          padding: EdgeInsets.only(top: 20.w),
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Icon(
                              Icons.location_on_outlined,
                              size: 32.w,
                              color: Config.colorText1,
                            ),
                            Expanded(
                              child: Text(
                                "广东省深圳市宝安区新安街道47区和丰小区一巷4号",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Container(
                    //商品信息
                    margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
                    decoration: BoxDecoration(
                      color: Config.colorWhite,
                      borderRadius: BorderRadius.circular(10.w),
                    ),
                    width: double.infinity,
                    padding:
                        EdgeInsets.only(left: 25.w, right: 25.w, top: 20.w),
                    child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Icon(
                              Icons.local_mall_outlined,
                              size: 32.w,
                              color: Config.colorMain,
                            ),
                            Padding(
                              padding: EdgeInsets.only(left: 10.w),
                            ),
                            Expanded(
                              child: Text(
                                "商家名称",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ),
                          ],
                        ),
                        Container(
                          width: double.infinity,
                          margin: EdgeInsets.only(top: 10.w),
                          height: 140.w,
                          child: ListView.builder(
                            physics: const NeverScrollableScrollPhysics(),
                            itemCount: productList.length,
                            scrollDirection: Axis.vertical,
                            itemBuilder: (BuildContext context, int index) {
                              return getListItem(0);
                            },
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    //价格和支付信息
                    margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
                    decoration: BoxDecoration(
                      color: Config.colorWhite,
                      borderRadius: BorderRadius.circular(10.w),
                    ),
                    child: Column(
                      children: [
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "商品总价",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "￥0.00",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ],
                          ),
                        ),
                        Divider(
                          color: Config.colorDivider,
                          height: 2.w,
                          thickness: 2.w,
                        ),
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "物流费用",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "￥0.00",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ],
                          ),
                        ),
                        Divider(
                          color: Config.colorDivider,
                          height: 2.w,
                          thickness: 2.w,
                        ),
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "订单总价",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "￥0.00",
                                style: TextStyle(
                                    fontSize: 24.sp, color: Colors.redAccent),
                              ),
                            ],
                          ),
                        ),
                        Divider(
                          color: Config.colorDivider,
                          height: 2.w,
                          thickness: 2.w,
                        ),
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "已支付",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "￥0.00",
                                style: TextStyle(
                                    fontSize: 24.sp, color: Colors.redAccent),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    //订单号和订单时间
                    margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
                    decoration: BoxDecoration(
                      color: Config.colorWhite,
                      borderRadius: BorderRadius.circular(10.w),
                    ),
                    child: Column(
                      children: [
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "订单编号",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "SFH20230205452653214",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ],
                          ),
                        ),
                        Divider(
                          color: Config.colorDivider,
                          height: 2.w,
                          thickness: 2.w,
                        ),
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "创建时间",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "2023-02-05 12:00:00",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ],
                          ),
                        ),
                        Divider(
                          color: Config.colorDivider,
                          height: 2.w,
                          thickness: 2.w,
                        ),
                        Container(
                          width: double.infinity,
                          padding: EdgeInsets.all(25.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "付款时间",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                              Text(
                                "2023-02-05 13:20:00",
                                style: TextStyle(fontSize: 24.sp),
                              ),
                            ],
                          ),
                        ),
                        Divider(
                          color: Config.colorDivider,
                          height: 2.w,
                          thickness: 2.w,
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 120.w,
                  ),
                ],
              ),
            ),
            Positioned(
              bottom: 0,
              child: Container(
                decoration: const BoxDecoration(color: Config.colorBg),
                height: 100.w,
                width: 750.w,
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(horizontal: 30.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Container(
                      margin: EdgeInsets.only(left: 15.w),
                      width: 140.w,
                      height: 55.w,
                      child: ElevatedButton(
                        clipBehavior: Clip.antiAlias,
                        onPressed: () => {
                          // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                          //     transition: TransitionType.inFromRight)
                        },
                        style: ButtonStyle(
                          elevation: MaterialStateProperty.all(0),
                          backgroundColor:
                              MaterialStateProperty.all(Colors.white),
                          shape: MaterialStateProperty.all(
                            RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(28.w),
                            ),
                          ),
                          side: MaterialStateProperty.all(
                            BorderSide(color: Config.colorText3, width: 2.w),
                          ),
                        ),
                        child: Text(
                          '取消订单',
                          style: TextStyle(
                              fontSize: 18.sp, color: Config.colorText3),
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 15.w),
                      width: 140.w,
                      height: 55.w,
                      child: ElevatedButton(
                        clipBehavior: Clip.antiAlias,
                        onPressed: () => {
                          // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                          //     transition: TransitionType.inFromRight)
                        },
                        style: ButtonStyle(
                          elevation: MaterialStateProperty.all(0),
                          backgroundColor:
                              MaterialStateProperty.all(Colors.white),
                          shape: MaterialStateProperty.all(
                            RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(28.w),
                            ),
                          ),
                          side: MaterialStateProperty.all(
                            BorderSide(color: Config.colorText3, width: 2.w),
                          ),
                        ),
                        child: Text(
                          '提醒发货',
                          style: TextStyle(
                              fontSize: 18.sp, color: Config.colorText3),
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 15.w),
                      width: 120.w,
                      height: 55.w,
                      child: ElevatedButton(
                        clipBehavior: Clip.antiAlias,
                        onPressed: () => {
                          // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                          //     transition: TransitionType.inFromRight)
                        },
                        style: ButtonStyle(
                          elevation: MaterialStateProperty.all(0),
                          backgroundColor:
                              MaterialStateProperty.all(Colors.white),
                          shape: MaterialStateProperty.all(
                            RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(28.w),
                            ),
                          ),
                          side: MaterialStateProperty.all(
                            BorderSide(color: Config.colorMain, width: 2.w),
                          ),
                        ),
                        child: Text(
                          '付款',
                          style: TextStyle(
                              fontSize: 18.sp, color: Config.colorMain),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
